package com.kelong;

import com.google.gson.Gson;

/**
 * @author User
 * @Auther: shiquan
 * @Date: 2024/10/24 - 10 - 24 -16:12
 */
public class ObjectDemo4 {
    public static void main(String[] args) throws CloneNotSupportedException {

        //1 先创建一个对象
        int[] data ={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0};
        User u1 = new User(1,"zhangsan","1234qwer","girl11",data);
        //克隆对象
        //1 重写object方法
        //2 让javabean类实现cloneable接口
        //创建原对象调用clone就ok
        User u2 = (User) u1.clone();


        //System.out.println(u1);
        //System.out.println(u2);

        //第三方工具
        Gson gson = new Gson();
        //把对象变成字符串
        String s = gson.toJson(u1);
        System.out.println(s);
        //把字符串变回对象
        User u3 = gson.fromJson(s, User.class);

        int[] arr = u1.getData();
        arr[0]=100;
        System.out.println(u3);

    }

}
